package com.ficus.road.maintain.dao;

import com.ficus.road.maintain.core.dao.BaseMongoDao;
import com.ficus.road.maintain.core.model.CarCoverage;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author xiawen yang
 * @date 2021/11/4 下午2:16
 */
@Component
public class CarCoverageDao extends BaseMongoDao<CarCoverage, String> {

    @Override
    public String getCollectionName() {
        return "car_coverage";
    }

    /**
     * 62天失效原因：最多统计上个月的覆盖率
     */
    @Override
    protected void indexOperation() {
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("timestamp", Sort.Direction.DESC).background());
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("creation_time", Sort.Direction.DESC).expire(62, TimeUnit.DAYS).background());
    }
}
